import { BeforeSoftRemove, Column, CreateDateColumn, DeleteDateColumn, UpdateDateColumn, VersionColumn } from 'typeorm';

import { BaseStatus } from '../enums';

export abstract class AuditBase {
  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updateAt: Date;

  @DeleteDateColumn()
  deleteAt: Date;

  @VersionColumn()
  version: number;

  @Column({ type: 'enum', enum: BaseStatus, default: BaseStatus.active })
  status: BaseStatus;

  /**
   * 操作备注
   */
  @Column({ type: 'text', nullable: true })
  remark: string;

  @BeforeSoftRemove()
  updateStatus() {
    this.status = BaseStatus.inactive;
  }
}
